{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">公告管理</li>
            <li class=""><a href="{:url('admin/adv/add')}">添加公告</a></li>
        </ul>
        <div class="layui-tab-content">

            <form class="layui-form layui-form-pane" action="{:url('/admin/adv')}" method="get">
                <div class="layui-inline">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-inline">
                        <select name="category">
                            <option value="0">全部</option>
                            {foreach name="category_list" item="vo"}
                            	<option value="{$vo.id}" {if condition="input('category') eq $vo['id']"}selected{/if}>{$vo.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">关键词</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keyword" value="{:input('keyword')}" placeholder="请输入关键词" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn">搜索</button>
                </div>
            </form>
            <hr>

            <form action="" method="post" class="ajax-form">
                <button type="button" class="layui-btn layui-btn-danger layui-btn-small ajax-action" data-action="{:url('admin/article/delete')}">删除</button>
                <div class="layui-tab-item layui-show">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="width: 15px;"><input type="checkbox" class="check-all"></th>
                            <th style="width: 30px;">ID</th>
                            <th>所属游戏</th>
                            <th>渠道</th>
                            <th style="width: 30px;">排序</th>
                            <th>标题</th>
                            <th>周期</th>
                            <th>发布</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="article_list" item="vo"}
                        <tr>
                            <td><input type="checkbox" name="id[]" value="{$vo.id}"></td>
                            <td>{$vo.id}</td>
                            <td>{if condition="$vo['gid'] gt 0"}{:get_game_filed($vo['gid'],'name')}{else}全部{/if}</td>
                            <td>{if condition="$vo['cid'] gt 0"}{:get_channel_name($vo['cid'])}{else}全部{/if}</td>
                            <td>{$vo.sort}</td>
                            <td>{$vo.title}</td>
                            <td>{$vo.star_date} - {$vo.end_date}</td>
                            <td>{if condition="$vo['status'] eq 0"}
                                <a style="color: #1068bf;cursor: pointer;" class="ajax-post" data-id="{$vo.id}" data-status="1" data-url="{:url('admin/article/check')}">上线</a>
                            {else}
                                <a style="color: #1068bf;cursor: pointer;" class="ajax-post" data-id="{$vo.id}" data-status="0" data-url="{:url('admin/article/check')}">下线</a>
                            {/if}</td>
                            <td>
                                <a href="{:url('admin/article/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                                <a href="{:url('admin/article/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                    <!--分页-->
                    {$article_list|raw}
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>

$('.ajax-post').click(function (){
    var url = $(this).data('url');
    var id = $(this).data('id');
    var status = $(this).data('status');
    $.post(url,{id:id,status:status},function(info){
        layer.msg(info.msg);
        setTimeout(() => {
            location.reload();
        }, 1000); // 1秒后刷新
    })
});

	;!function(){
var layer = layui.layer,
    element = layui.element,
    laydate = layui.laydate,
    form = layui.form;
	form.on('select(filter)', function(data){
  console.log(data.elem); //得到select原始DOM对象
  console.log(data.value); //得到被选中的值
  console.log(data.othis); //得到美化后的DOM对象
});
}
</script>
{/block}